#include <iostream>

#include "ros/ros.h"
#include "demo/User.h"

void topicCallback(const demo::User::ConstPtr &message) {
    if (message.get() != nullptr) {
        const std::string &userName = message.get()->name;
        const uint32_t userAge = message.get()->age;
        ROS_INFO("Subscribe topic message success, name: %s, age: %d", userName.c_str(), userAge);
    }
}

int main(int argc, char* argv[]) {
    std::string nodeName = "subscriber";
    ros::init(argc, argv, nodeName);
    ros::NodeHandle nodeHandle;
    std::string topicName = "demo3";
    uint32_t queueSize = 1000;
    const ros::Subscriber &subscriber = nodeHandle.subscribe<demo::User>(topicName, queueSize, topicCallback);
    ros::spin();

    return EXIT_SUCCESS;
}
